package ar.uba.fi.taller2.ftrs.repo;
import ar.uba.fi.taller2.ftrs.common.*;

import java.io.File;

public class Repositorio {
	
	private String repname;
	private String path;
	
	public String getName() {
		return repname;
	}

	public void setName(String name) {
		this.repname = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public Repositorio(String path,String name){
		this.repname = name;
		this.path = path;
	}
	
	public Repositorio(String name){
		this.repname = name;
		String WorkingDirectory = Parameters.getParametros().getMessage("WORKING_DIRECTORY", 1);
		if (WorkingDirectory==null || WorkingDirectory.length()==0) {
			WorkingDirectory = RepositoryManager.DEFAULT_WD;
		}		
		this.path = WorkingDirectory+File.separator+this.repname;
	}
	
	private void addObject(String fileName) {
		
	}
	
	private void removeRepository(String repName) {
		
	}
	private void renameRepository(String repName1,String repName2) {
		
	}
	public String[] getContent(){
		File dir = new File(this.path);
		String[] children=null;
		if (dir.isDirectory()) 
			children = dir.list();
		return children;		
	}
	
	public static String[] getContentFullPath(String path){
		File dir = new File(path+File.separator+"input");
		String[] children=null;
		if (dir.isDirectory()) 
			children = dir.list();
		for (int i=0;i<children.length;i++)
			children[i]=path+File.separator+"input"+File.separator+children[i];
		return children;		
	}	

	public static String pathToName(String path){		
		return path.substring(path.lastIndexOf(File.separator)+1);		
	}
	
	public static String pathToBasedir(String path){
		return path.substring(0, path.lastIndexOf(File.separator));
	}

	
	public String toString(){
		return repname;
	}
}
